public class Solution1669 {

    public static class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }


    public ListNode mergeInBetween(ListNode list1, int a, int b, ListNode list2) {
        ListNode listNode=new ListNode(0,list1);
        ListNode head=listNode;
        for (int i = 0; i < a; i++) {
            listNode=listNode.next;
        }
        ListNode listNode1=list1;
        for (int i = 0; i < b + 1; i++) {
            listNode1=listNode1.next;
        }
        listNode.next=list2;
        while (list2.next!=null){
            list2=list2.next;
        }
        list2.next=listNode1;
        return head.next;
    }

    public static void main(String[] args) {
        System.out.println(new Solution1669().mergeInBetween(new ListNode(0,new ListNode(1,new ListNode(2,new ListNode(3,new ListNode(4,new ListNode(5)))))),3,4,new ListNode(10000,new ListNode(10001,new ListNode(10002)))).next.next.next.val);
    }
}
